<template>
  <el-col>
    <el-form :model="form" label-width="120px">
      <el-form-item label="用户">
        {{ form.id }}
      </el-form-item>
      <el-form-item label="充电量">
        <el-input v-model="form.amount" type="number"/>
        单位：度
      </el-form-item>
      <el-form-item label="充电模式">
        <el-radio-group v-model="form.mode">
          <el-radio label="T"/>
          <el-radio label="F"/>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">预约</el-button>
      </el-form-item>
    </el-form>
  </el-col>
</template>

<script>
import axios from 'axios';
import Global from './Global.vue';

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: 'Appointment',
  data() {
    return {
      form: {
        id: Global.id,
        mode: '',
        amount: '',
      },
    };
  },
  methods: {
    onSubmit() {
      const path = '/api/send_appoint';
      if (this.form.amount !== '' && this.form.mode !== '') {
        axios.post(path, this.form)
          .then((res) => {
            if (res.data.ok) {
              Global.mode = this.form.mode;
              Global.amount = this.form.amount;
              this.$message.success('预约成功');
            } else {
              this.$message.success('预约失败');
            }
          })
          .catch((error) => {
            // eslint-disable-next-line
            console.error(error);
          });
      } else {
        this.$message.warning('充电量和充电模式不能为空');
      }
    },
  },
};

</script>

<style scoped>

</style>
